package com.travelsky.airchina.boarding.dao.impl.hibernate;


import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.travelsky.airchina.boarding.dao.RoleDAO;
import com.travelsky.airchina.boarding.domain.Role;
import com.travelsky.airchina.boarding.domain.RoleColumn;

@Repository("roleDAO")
public class RoleDAOImpl extends GenericDAOHibernate<Role, Long,RoleDAO> implements RoleDAO {
	@Autowired
	public RoleDAOImpl(SessionFactory sessionFactory){
		this.setSessionFactory(sessionFactory);
	}

	@SuppressWarnings("unchecked")
	public List<Role> findAllRoles(String status) {
		String hql = "from Role where status = ? order by sortOrder";
		return this.getHibernateTemplate().find(hql,status);
	}

	public int getRoleSum() {
		return this.countHqlQuery("select count(id) from Role", null);
	}

	@SuppressWarnings("unchecked")
	public List<RoleColumn> findColumnByRoleId(Long roleId) {
		String hql = "from RoleColumn where roleId = ?";
		return this.getHibernateTemplate().find(hql,roleId);
	}

	public void deleteRoleColumnByRoleId(Long roleId) {
		String hql = "delete from RoleColumn where roleId = ?";
		this.getHibernateTemplate().bulkUpdate(hql, roleId);
	}

	public void saveRoleColumn(RoleColumn roleColumn) {
		this.getHibernateTemplate().save(roleColumn);
	}
}
